{% extends "common/layout_main.html" %}
{% block content %}
<div class="row  border-bottom">
    <div class="col-lg-12">
        <div class="tab_title">
            <ul class="nav nav-pills">
                <li>
                    <a href="{{ url_for('user_page.edit') }}">信息编辑</a>
                </li>
                <li class="current">
                    <a href="{{ url_for('user_page.resetPwd') }}">修改密码</a>
                </li>
            </ul>
        </div>
    </div>
</div>
<div class="row m-t  user_reset_pwd_wrap">
    <div class="col-lg-12">
        <h2 class="text-center">修改密码</h2>
        <div class="form-horizontal m-t m-b">
            <div class="form-group">
                <label class="col-lg-2 control-label">账号:</label>
                <div class="col-lg-10">
                    <label class="control-label">{{ current_user.login_name }}</label>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <label class="col-lg-2 control-label">手机:</label>
                <div class="col-lg-10">
                    <label class="control-label">{{ current_user.mobile }}</label>
                </div>
            </div>
            <div class="hr-line-dashed"></div>

            <div class="form-group">
                <label class="col-lg-2 control-label">原密码:</label>
                <div class="col-lg-10">
                    <input type="password" id="old_password" class="form-control" placeholder="请输入6-16位旧密码" value="">
                </div>
            </div>
            <div class="hr-line-dashed"></div>

            <div class="form-group">
                <label class="col-lg-2 control-label">新密码:</label>
                <div class="col-lg-10">
                    <input type="password" id="new_password" class="form-control" placeholder="请输入6-16位新密码" value="">
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <div class="col-lg-4 col-lg-offset-2">
                    <button class="btn btn-w-m btn-outline btn-primary" id="save">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block js %}
<script>
	var user_reset_pwd= {
		init:function(){
			this.eventBind()
		},
		eventBind:function(){
            $(".user_reset_pwd_wrap #save").click(function(){
                var old_password_target = $(".user_reset_pwd_wrap #old_password");
                var new_password_target = $(".user_reset_pwd_wrap #new_password");
                var old_password = old_password_target.val()
                var new_password = new_password_target.val()

                if (old_password == "" || old_password.length <6 || old_password.length > 16){
                    common_ops.tip("请输入正确位数的旧密码！",old_password_target)
                    return ;
                }

                if (new_password == "" || new_password.length <6 || new_password.length > 16){
                    common_ops.tip("请输入正确位数的新密码！",new_password_target)
                    return ;
                }

                if (new_password == old_password){
                    common_ops.alert("新密码和旧密码不能相同哦！")
                    return ;
                }

                $.ajax({
                    url:"/user/reset-pwd",
                    type:"POST",
                    data:{"old_password":old_password,"new_password":new_password},
                    dataType:"json",
                    success:function(res){
                        var callback = null
                        if(res.code == 200){
                            callback = function(){
                                window.location.href = "/user/login-out"
                            }
                            common_ops.alert(res.msg,callback)
                        }
                        if(res.code == -1){
                            common_ops.alert(res.msg)
                        }
                    }
                })
            });
		}
	}
    $(document).ready(function(){
        user_reset_pwd.init();
    })

</script>
{% endblock %}

